home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / ff_clip.h < prev    next >
C/C++ Source or Header  |  1999-01-01  |  4KB  |  117 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  FF_CLIP.H - Form Factor Polygon Clipper Class
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              96/02/14 - Version 1.02C release.
  12. //              96/04/01 - Version 1.03A release.
  13. //
  14. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  15. //              Borland C++ Version 4.5
  16. //
  17. //  Author:     Ian Ashdown, P.Eng.
  18. //              byHeart Software Limited
  19. //              620 Ballantree Road
  20. //              West Vancouver, B.C.
  21. //              Canada V7S 1W3
  22. //              Tel. (604) 922-6148
  23. //              Fax. (604) 987-7621
  24. //
  25. //  Copyright 1994-1996 byHeart Software Limited
  26. //
  27. //  The following source code has been derived from:
  28. //
  29. //    Ashdown, I. 1994. Radiosity: A Programmer's
  30. //    Perspective. New York, NY: John Wiley & Sons.
  31. //
  32. //  It may be freely copied, redistributed, and/or modified
  33. //  for personal use ONLY, as long as the copyright notice
  34. //  is included with all source code files.
  35. //
  36. ////////////////////////////////////////////////////////////
  37.  
  38. #ifndef _FF_CLIP_H
  39. #define _FF_CLIP_H
  40.  
  41. #include "ff_poly.h"
  42.  
  43. // View normalization parameters
  44. static const double FPD = -0.99;
  45. static const double BPD = MAX_VALUE;
  46. static const double EYE = -1.0;
  47. static const double SN = (EYE - BPD) * (EYE - FPD) / (EYE *
  48.     EYE * (BPD - FPD));
  49. static const double RN = FPD * (EYE - BPD) / (EYE * (FPD -
  50.     BPD));
  51.  
  52. class FormClipEdge      // Edge-plane clipper
  53. {
  54.   private:
  55.     FormClipEdge *pnext;        // Next clipper pointer
  56.     Vector4 normal;             // Plane normal
  57.     Vector4 first;              // First vertex
  58.     Vector4 start;              // Start vertex
  59.     BOOL first_inside;          // First vertex inside flag
  60.     BOOL start_inside;          // Start vertex inside flag
  61.     BOOL first_flag;            // First vertex seen flag
  62.  
  63.     BOOL IsInside( Vector4 &v )
  64.     { return (Dot(normal, v) >= 0.0); }
  65.     Vector4 Intersect( Vector4 &, Vector4 & );
  66.     void Output( Vector4 &, FormPoly & );
  67.  
  68.   public:
  69.     FormClipEdge() { first_flag = FALSE; }
  70.  
  71.     void Add( FormClipEdge *pc ) { pnext = pc; }
  72.     void Clip( Vector4 &, FormPoly & );
  73.     void Close( FormPoly & );
  74.     void SetNormal( Vector4 &n ) { normal = n; }
  75. };
  76.  
  77. class FormClip  // Form factor polygon clipper
  78. {
  79.   protected:
  80.     int num_vert;               // # of polygon vertices
  81.     Vector3 u, v, n;            // View system co-ordinates
  82.     double vtm[4][4];           // Transformation matrix
  83.     FormClipEdge clipper[5];    // Clipper array
  84.     FormClipEdge *pclip;        // Clipper list head pointer
  85.     Point3 center;              // Polygon center
  86.  
  87.     Vector3 RandomVector()      // Generate random vector
  88.     {
  89.       Vector3 temp;     // Temporary vector
  90.  
  91.       temp.SetX(GetNormRand() * 2.0 - 1.0);
  92.       temp.SetY(GetNormRand() * 2.0 - 1.0);
  93.       temp.SetZ(GetNormRand() * 2.0 - 1.0);
  94.  
  95.       return temp;
  96.     }
  97.  
  98.   public:
  99.     BOOL BackFaceCull( Patch3 *ppatch )
  100.     {
  101.       Vector3 view;     // View vector
  102.       
  103.       // Calculate view vector
  104.       view = Vector3(ppatch->GetVertexPtr(0)->GetPosn(),
  105.           center);
  106.           
  107.       // Indicate whether patch is backface
  108.       return (Dot(ppatch->GetNormal(), view) < MIN_VALUE) ?
  109.           TRUE : FALSE;
  110.     }
  111.  
  112.     int Clip( Element3 *, FormPoly &, WORD );
  113. };
  114.  
  115. #endif
  116.  
  117.